<?php

namespace App\Http\Controllers\Backend\EdgeManage;

use App\Http\Controllers\Controller;
use App\Http\Repositories\EdgeManage\CostSettingRepo;
use App\Http\Requests\Validators\Backend\EdgeManage\CostSettingValidator;
use Illuminate\Http\Request;

/**
 * 提成/奖励相关
 */
class CostSettingController extends Controller
{
    const VALIDATOR = CostSettingValidator::class;

    public function __construct()
    {
        $this->self_repo = new CostSettingRepo;
    }

    public function search(Request $request)
    {
        //参数验证
        $args = $request->only('type', 'status', 'ratio', 'value', 'begin_time', 'end_time');
        $this->my_validate($args, 'searchRules');
        return $this->self_repo->search($args);
    }

    public function store(Request $request)
    {
        //参数验证
        $args = $request->only('type', 'status', 'ratio', 'value');
        $this->my_validate($args, 'storeRules');

        //添加数据
        return $this->returnResponse($this->self_repo->createOne($args));
    }

    public function delete($id)
    {
        return $this->self_repo->deleteById($id);
    }

    public function edit(Request $request, $id)
    {
        //参数验证
        $args = $request->only('type', 'status', 'ratio', 'value');
        $this->my_validate($args, 'editRules');
        //根据id修改数据
        return $this->returnResponse($this->self_repo->editById($id, $args));
    }
}
